"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerManager = void 0;
const ServerConfig_1 = require("../config/ServerConfig");
const SocketClientReqManager_1 = require("../engine/socketclient/SocketClientReqManager");
const Logger_1 = require("../engine/utils/Logger");
const GameHttpHelper_1 = require("../game/helper/GameHttpHelper");
class ServerManager {
    // public initServerSockets() {
    //     let hall_server_list: Array<ServerConfig> = ServerConfig.hall_server_List;
    //     for (let i = 0; i < hall_server_list.length; i++) {
    //         let server: ServerConfig = hall_server_list[i]
    //         if (server.id != ServerConfig.nowServerConfig.id) {
    //             SocketClientReqManager.instance.req_server_login(server)
    //         }
    //     }
    // }
    set_allserver_status(status) {
        return __awaiter(this, void 0, void 0, function* () {
            // let all_server_list: Array<ServerConfig> = ServerConfig.getAllSocketServer();
            // for (let i = 0; i < all_server_list.length; i++) {
            //     let server: ServerConfig = all_server_list[i]
            //     if (server.id == ServerConfig.nowServerConfig.id) {
            //         server.status = status
            //     } else {
            //         SocketClientReqManager.instance.req_server_set_server_status(status, server)
            //     }
            // }
        });
    }
    getServerListOnlineNum(serverList) {
        return __awaiter(this, void 0, void 0, function* () {
            let onlineNum = 0;
            Logger_1.Logger.log("get_all_server_online_num=serverList=", serverList);
            for (let i = 0; i < serverList.length; i++) {
                let server = serverList[i];
                let response = yield GameHttpHelper_1.GameHttpHelper.get_online_num(server.getInternalUrl() + "/online");
                Logger_1.Logger.log("get_all_server_online_num==", response);
                onlineNum += response["count"];
            }
            return onlineNum;
        });
    }
    get_all_server_online_num() {
        return __awaiter(this, void 0, void 0, function* () {
            let onlineNum = 0;
            let server_list = ServerConfig_1.ServerConfig.hall_server_List;
            onlineNum += yield this.getServerListOnlineNum(server_list);
            return onlineNum;
        });
    }
    is_in_server(account) {
        return __awaiter(this, void 0, void 0, function* () {
            let resultServerConfig = null;
            let hall_server_list = ServerConfig_1.ServerConfig.hall_server_List;
            for (let i = 0; i < hall_server_list.length; i++) {
                let server = hall_server_list[i];
                let response = yield SocketClientReqManager_1.SocketClientReqManager.instance.req_server_is_in_server(account, server);
                if (response && response["isIn"]) {
                    let isIn = response["isIn"];
                    if (isIn) {
                        resultServerConfig = server;
                        return resultServerConfig;
                    }
                }
            }
            return resultServerConfig;
        });
    }
}
exports.ServerManager = ServerManager;
ServerManager.instance = new ServerManager();
